home *** CD-ROM | disk | FTP | other *** search
/ InterCD 1999 March / marchl_1999.iso / Site Building / Mallsurfer Shop / _SETUP.1 / common_js.txt < prev    next >
Encoding:
Text File  |  1998-12-03  |  4.2 KB  |  180 lines

  1. MaxCartItems = 15;
  2. ReferrerLife = 30;
  3.  
  4. function SaveReferrer()
  5. {
  6.     CookieName = 'Referrer';
  7.  
  8.     CookieValue = GetCookie(CookieName);
  9.     if(CookieValue == null)
  10.     {
  11.         // if no cookie present for referrer
  12.         CookieValue = document.referrer;
  13.     }
  14.  
  15.         var expdate = new Date();
  16.         expdate.setDate(ReferrerLife);
  17.  
  18.         SetCookie(CookieName,CookieValue,expdate);
  19. }
  20.  
  21. function getCookieVal (offset) {
  22.   var endstr = document.cookie.indexOf (";", offset);
  23.   if (endstr == -1)
  24.     endstr = document.cookie.length;
  25.   return unescape(document.cookie.substring(offset, endstr));
  26. }
  27.  
  28. function GetCookie (name) {
  29.   var arg = name + "=";
  30.   var alen = arg.length;
  31.   var clen = document.cookie.length;
  32.   var i = 0;
  33.   while (i < clen) {
  34.     var j = i + alen;
  35.        if (document.cookie.substring(i, j) == arg)
  36.      return getCookieVal (j);
  37.     i = document.cookie.indexOf(" ", i) + 1;
  38.     if (i == 0) break; 
  39.   }
  40.   return null;
  41. }
  42.  
  43. function SetCookie (name, value) {
  44.   var argv = SetCookie.arguments;
  45.   var argc = SetCookie.arguments.length;
  46.   var expires = (argc > 2) ? argv[2] : null;
  47.   var path = (argc > 3) ? argv[3] : null;
  48.   var domain = (argc > 4) ? argv[4] : null;
  49.   var secure = (argc > 5) ? argv[5] : false;
  50.   document.cookie = name + "=" + escape (value) +
  51.     ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
  52.     ((path == null) ? "" : ("; path=" + path)) +
  53.     ((domain == null) ? "" : ("; domain=" + domain)) +
  54.     ((secure == true) ? "; secure" : "");
  55. }
  56.  
  57. function DeleteCookie (name) {
  58.   var exp = new Date();
  59.   exp.setTime (exp.getTime() - 1);  // This cookie is history
  60.   var cval = GetCookie (name);
  61.   if (cval != null)
  62.     document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
  63. }
  64.  
  65. function AddItem(ID,Sdesc,Price,Qty,Weight,WeightUnit)
  66. {
  67.     if (Qty <= 0) 
  68.     {
  69.         rc = alert('The Quantity must be greater than 0');
  70.         return false;
  71.     }
  72.  
  73.     if (confirm('###ADDING### :' +Qty+ ': "' +Sdesc+ '".')) 
  74.     {
  75.         for(NumItems = 0; NumItems<=MaxCartItems; NumItems++)
  76.         {
  77.             if(NumItems == MaxCartItems)
  78.             {
  79. alert('Maximum of '+MaxCartItems+' different items can fit in the shopping cart, please go to the Checkout Counter and submit your order.  Then empty your cart and shop some more later.');
  80.             }
  81.             else
  82.             {
  83.                 CookieName = 'Cart' +NumItems;
  84.                 CookieValue = GetCookie(CookieName);
  85.                 if(CookieValue == null)
  86.                 {
  87.                     CookieValue = "["+ID+"└"+Sdesc+"┴"+Price+"┬"+Qty+"├"+Weight+"─"+WeightUnit+"]";
  88.                     SetCookie(CookieName,CookieValue);
  89.                     break;
  90.                 }
  91.             }
  92.         }
  93.     }
  94.     return true;
  95. }
  96.  
  97. function FloatFormat(expr,decplaces)
  98. {
  99.     var str = "" + Math.round(eval(expr) * Math.pow(10,decplaces));
  100.     while(str.length <= decplaces)
  101.     {
  102.         str = "0" + str;
  103.     }
  104.  
  105.     var decpoint = str.length - decplaces;
  106.     return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
  107. }
  108.  
  109. rsize = 10;        // rounding size
  110. oz_factor = 1;        // ounces to ounces
  111. lbs_factor = 0.0625;        // ounces to pounds
  112. mg_factor = 28349.5;        // ounces to miligrams
  113. g_factor = 28.3495;        // ounces to grams
  114. kg_factor = .0283495;    // ounces to kilograms
  115. var UnitSize;    // weight number being converted
  116. var OldUnit;    // converting from
  117. var NewUnit;    // converting to
  118. var NewUnitSize;    // new weight in new unit
  119.  
  120. function ConvertUnit(UnitSize,OldUnit,NewUnit)
  121. {
  122. // possible units
  123. // oz
  124. // lbs
  125. // mg
  126. // g
  127. // kg
  128.  
  129.     NewUnitSize = 0;
  130.     TmpUnitSize = 0;
  131.  
  132.     // if not oz, convert to oz first
  133.     if(OldUnit != 'oz')
  134.     {
  135.         if(OldUnit == 'lbs')
  136.         {
  137.             TmpUnitSize = UnitSize / lbs_factor;
  138.         }
  139.         else if(OldUnit == 'mg')
  140.         {
  141.             TmpUnitSize = UnitSize / mg_factor; 
  142.         }
  143.         else if(OldUnit == 'g')
  144.         {
  145.             TmpUnitSize = UnitSize / g_factor; 
  146.         }
  147.         else if(OldUnit == 'kg')
  148.         {
  149.             TmpUnitSize = UnitSize / kg_factor; 
  150.         }
  151.     }
  152.     else
  153.     {
  154.         // if oz, keep as is
  155.         TmpUnitSize = UnitSize;
  156.     }
  157.  
  158.     // since TmpUnitSize is now oz, convert to NewUnit;
  159.     if(NewUnit == 'oz')
  160.     {
  161.         NewUnitSize = TmpUnitSize;
  162.     }
  163.     else if(NewUnit == 'lbs')
  164.     {
  165.         NewUnitSize = TmpUnitSize * lbs_factor;
  166.     }
  167.     else if(NewUnit == 'mg')
  168.     {
  169.         NewUnitSize = TmpUnitSize * mg_factor;
  170.     }    
  171.     else if(NewUnit == 'g')
  172.     {
  173.         NewUnitSize = TmpUnitSize * g_factor;
  174.     }    
  175.     else if(NewUnit == 'kg')
  176.     {
  177.         NewUnitSize = TmpUnitSize * kg_factor;
  178.     }    
  179. }
  180.